package cc.yugu.yhdw.common.protocol.msg02;

import cc.yugu.yhdw.common.protocol.MsgCode;
import cc.yugu.yhdw.common.tool.netty.TypeOperator;
import io.netty.buffer.ByteBuf;

import java.util.ArrayList;
import java.util.List;

public class Msg022000030 extends Msg022 {
    public List<Battery> batteryList = new ArrayList<Battery>();
    public int allCount;
    public int freeCount;
    public int chargeCount;
    public int fullCount;
    public int busyCount;

    @Override
    public int getMsgCode() {
        return MsgCode.MSG_022000030.getCode();
    }

    @Override
    public void writeData(ByteBuf buffer) {
        writeRtn(buffer);

        buffer.writeInt(batteryList.size());
        for (Battery e : batteryList) {
            e.write(buffer);
        }
        buffer.writeInt(allCount);
        buffer.writeInt(freeCount);
        buffer.writeInt(chargeCount);
        buffer.writeInt(fullCount);
        buffer.writeInt(busyCount);
    }

    public static class Battery extends TypeOperator {

        public String id;
        public double distance;
        public byte state;
        public byte temp;
        public byte volume;

        public void write(ByteBuf buffer) {
            writeString(buffer, id);
            buffer.writeDouble(distance);
            buffer.writeByte(state);
            buffer.writeByte(temp);
            buffer.writeByte(volume);
        }
    }
}
